package com.xgame.server.dbtool;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xgame.server.db.mapper.GrowupwelfMapper;
import com.xgame.server.db.model.Account;
import com.xgame.server.db.model.Growupwelf;
import com.xgame.server.db.model.Hero;
import com.xgame.server.db.model.User;
import com.xgame.server.netty.proto.Game;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Component
public class GrowupwelfCsTool {
    @Resource
    private GrowupwelfMapper growupwelfMapper;

    public Integer insertGrowUpWelf(Game.GrowUpWelfCs data) throws Exception {
        //1.更新用户表
        Growupwelf map = new Growupwelf();
        map.setAccount(data.getAccount());
        map.setPlayerId(data.getPlayerID());
        map.setFlag(data.getFlag());
        map.setLv5(data.getLv5());
        map.setLv10(data.getLv10());
        map.setLv15(data.getLv15());
        map.setLv20(data.getLv20());
        map.setLv25(data.getLv25());
        map.setLv30(data.getLv30());
        map.setLv35(data.getLv35());
        map.setLv40(data.getLv40());
        map.setLv45(data.getLv45());
        map.setLv50(data.getLv50());
        map.setLv55(data.getLv55());
        map.setLv60(data.getLv60());
        map.setLv70(data.getLv70());

        return growupwelfMapper.insert(map);
    }

    //更新玩家记录
    public Integer updateGrowUpWelf(Game.GrowUpWelfCs data) throws Exception {
        EntityWrapper<Growupwelf> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", data.getAccount());

        Growupwelf map = new Growupwelf();
        map.setAccount(data.getAccount());
        map.setPlayerId(data.getPlayerID());
        map.setFlag(data.getFlag());
        map.setLv5(data.getLv5());
        map.setLv10(data.getLv10());
        map.setLv15(data.getLv15());
        map.setLv20(data.getLv20());
        map.setLv25(data.getLv25());
        map.setLv30(data.getLv30());
        map.setLv35(data.getLv35());
        map.setLv40(data.getLv40());
        map.setLv45(data.getLv45());
        map.setLv50(data.getLv50());
        map.setLv55(data.getLv55());
        map.setLv60(data.getLv60());
        map.setLv70(data.getLv70());

        return growupwelfMapper.update(map, userWrapper);
    }

    //查询记录
    public List<Growupwelf> selectGrowupwelf(String account) throws Exception {
        EntityWrapper<Growupwelf> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return growupwelfMapper.selectList(userWrapper);
    }
}
